package com.neusoft.elmboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.User;
import com.neusoft.elmboot.service.UserService;

@RestController
@RequestMapping("/User")
public class UserController {
    
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/userId/{userId}/password/{password}" ,method = RequestMethod.GET)
    public User getUserByIdByPass( 
        @PathVariable("userId") String userId,
        @PathVariable("password") String password) throws Exception{
        return userService.getUserByIdByPass(userId, password);
    }
    
    @RequestMapping(value = "/userId/{userId}",method = RequestMethod.GET)
    public int getUserById(@PathVariable("userId") String userId) throws Exception{
        return userService.getUserById(userId);
    }
    
    @RequestMapping(method = RequestMethod.POST)
    public int saveUser(User user) throws Exception{
        return userService.saveUser(user);
    }
    
    @RequestMapping(value = "/userId/userName", method = RequestMethod.PUT)
    public int updateUserMsg(String userId,String userName){
        return userService.updateUserMsg(userId, userName);
    }

    @RequestMapping(value = "/userId/oldPass/newPass", method = RequestMethod.PUT)
    public int updateUserPassword(String userId,String oldPass,String newPass) throws Exception{
        return userService.updateUserPassword(userId, oldPass, newPass);
    }
}
